package com.hc.cosmetichospital.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hc.cosmetichospital.common.SerialNumber;
import com.hc.cosmetichospital.pojo.Clients;
import com.hc.cosmetichospital.pojo.Consulting;
import com.hc.cosmetichospital.pojo.ResultMap;
import com.hc.cosmetichospital.pojo.Staff;
import com.hc.cosmetichospital.service.ClientsService;
import com.hc.cosmetichospital.service.ConsultingService;
import com.hc.cosmetichospital.service.MemberService;
import com.hc.cosmetichospital.vo.ClientsVo;
import com.hc.cosmetichospital.vo.ConsultingVo;

@Controller
@RequestMapping("/clients")
public class ClientsController {

	@Autowired
	private ClientsService clientsService;
	
	@Autowired
	private ConsultingService consultingService;
	
	@Autowired
	private MemberService memberService;
	
	
	@RequestMapping("/list")
	@ResponseBody
	public ResultMap<Clients> getClientsAll(ClientsVo clientsVo){
		return clientsService.getClientsList(clientsVo);
	}
	
	@RequestMapping("/select")
	@ResponseBody
	public List<Clients> getClientsSelect(){
		return clientsService.getClientsSelect();
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public int addgetClients(ConsultingVo consultingVo,HttpServletRequest request){
		Staff user = (Staff)request.getSession().getAttribute("user");
		
		consultingVo.setClientManage(user.getStid());
		consultingVo.setClientType(1);
		consultingVo.setStatus(1);
		consultingVo.setNo(SerialNumber.getSerial());
		consultingVo.setConsultingManage(user.getStid());
		
		int retult = clientsService.addClients(consultingVo);
		if(retult==0) {
			return 0;
		}
		
		int retutl2 = consultingService.addConsulting(consultingVo);
		if(retutl2==0) {
			return 0;
		}
		return 1;
	}
	
	
	@RequestMapping("/delete")
	@ResponseBody
	public int delClients(Integer id){
		int retult = 0;
		retult+=clientsService.deleteClients(id);
		retult+=consultingService.deleteClientConsulting(id);
		retult+=memberService.deleteClientMember(id);
		
		if(retult>=3) {
			return 1;
		}else {
			return 0;
		}
	}
	
	
	@RequestMapping("/consulting")
	@ResponseBody
	public ResultMap<Consulting> getConsultingById(Integer id){
		return consultingService.getConsultingById(id);
	}
}


 